<cfparam name="f" default="docs">
<cfparam name = "Dir" default="/">
<cfparam name = "showfolders" default="0">
<cfif isdefined('cookie.folders')>
  <cfif cookie.folders IS 1>
    <cfset showfolders = 1>
  </cfif>
  <cfif cookie.folders IS 0>
    <cfset showfolders = 0>
  </cfif>
</cfif>
<cfset ptype = "Admin">
<cfset p = "#request.adminpath##f##dir#">
<!---full path to the folder where the documents are--->
<cfdirectory action="list" directory="#p#" name="qfiles" filter="*.cfm" type="file" sort="name ACS">
<cfdirectory action="list" directory="#p#" name="qrydirectories" sort="name ASC" type="dir">
<cfinclude template="header.cfm">
<div style="display: none; border: 1px solid #003366; padding: 20px;" id="newpage">
  <cfinclude template="../frm/wizard_layout.cfm">
</div>
<div style="display: none; border: 1px solid #003366; padding: 20px;" id="newfolder">
  <cfinclude template="../frm/newfolder.cfm">
</div>
<table width="100%" cellpadding="4" cellspacing="0" border="0">
  <!---Display the list of folders in this directory--->
  <tr style="cursor: pointer;" <cfoutput>onclick="expandcollapse('folders','expandcollapseimg','#request.absolutepath#images/defaults/');"</cfoutput>>
    <td id="columnheaders" colspan="2"><cfoutput>#ptype#</cfoutput> Folders (Current folder: <cfoutput>#f##dir#</cfoutput>}</td>
    <td id="columnheaders" style="text-align: right;"><cfif qryDirectories.recordcount GT 0>
        <cfoutput><img src="#request.absolutepath#images/defaults/collapse.gif" border="0" id="expandcollapseimg" /></cfoutput>
      </cfif>
    </td>
  </tr>
  <cfif NOT Dir IS '/'>
    <!---figure out which directory is up one from this one--->
    <cfset PathLength = listlen(dir, "/")>
    <cfset UpDirName = ListDeleteAt(dir, PathLength, '/')>
    <cfif UpDirName IS ''>
      <cfset UpDirName = '/'>
    </cfif>
    <tr>
      <td valign="middle" colspan="3" class="menu_cell"><img src="images/folder_up.png" align="absmiddle"> <cfoutput><a href = "index.cfm?c=admindocs&a=default&Dir=#UpDirName#">[Parent Folder]</a></cfoutput></td>
    </tr>
  </cfif>
  <cfoutput Query = "qryDirectories">
    <cfset ImageName = 'folder.png'>
    <tr>
      <td colspan="3"><div id="folders" <cfif showfolders IS 0>style="display: none;"</cfif>>
          <table width="100%" cellpadding="2" cellspacing="0">
            <tr class="menu_row" onMouseOver="this.className = 'menu_row_over2';" onMouseOut="this.className = 'menu_row';">
              <td class="menu_cell" onclick="window.location.href = 'index.cfm?c=admindocs&a=default&Dir=#Dir##Name#/';"><img src="images/#ImageName#" align="absmiddle"> <a href = "index.cfm?c=admindocs&a=default&Dir=#Dir##Name#/">#Name#</a> </td>
              <td width="15%" class="menu_cell" style="text-align: right;"><a href = "##" onclick="javascript:ConfirmDeleteAdminPageFolder('#UrlEncodedFormat(dir)#','#name#', '#f#');"><img src="images/folder_delete.png" alt="Delete this folder" title="Delete this folder" border="0"></a> </td>
            </tr>
          </table>
        </div>
    </tr>
  </cfoutput>
  <tr>
    <td colspan="3"><cfif qryDirectories.recordcount IS 0>
        <div id="messages_info">No folders found in current path.</div>
        <cfelse>
        <cfif showfolders IS 0>
          <cfoutput>
            <div id="expandcollapse_msg" style="display: block;" onclick="expandcollapse('folders','expandcollapseimg','#request.absolutepath#images/defaults/');">Click to Expand</div>
          </cfoutput>
        </cfif>
      </cfif>
    </td>
  </tr>
  <tr>
    <td id="columnheaders">File Name (<cfoutput>#ptype#</cfoutput> Pages)</td>
    <td id="columnheaders" width="35%">Date Last Modified</td>
    <td id="columnheaders" width="15%"></td>
  </tr>
  <cfloop query="qfiles">
    <cfoutput>
      <tr class="menu_row" onMouseOver="this.className = 'menu_row_over2';" onMouseOut="this.className = 'menu_row';">
        <td class="menu_cell"><cfset idname=replacenocase(name, ".cfm", "")>
          <div> <span class="filename"  id = "norename_#idname#" style="display: block;" onclick="window.location.href = 'index.cfm?c=admindocs&a=edit&page_name=#name#&f=#f#&dir=#dir#';"> <img src = "images/filetypes/document_html.png" align="absmiddle" />&nbsp;#name# </span>
            <!---rename form--->
            <span class="filename" id="rename_#idname#" style="display: none;">
            <cfset FieldSize = #len(name)# + 10>
            <cfif FieldSize GT 30>
              <cfset FieldSize = 30>
            </cfif>
            <form name = "renameform_#idname#" id="renameform_#idname#" action="index.cfm?c=admindocs&a=rename&f=#f#&page_name=#name#" method="Post">
              <input type="hidden" name="the_action" id="the_action" value="" />
              <input type = "text" size="#FieldSize#" name="new_name" id="new_name" value="#name#">
              <img src="images/okay.png" alt="Rename File" title="Rename File" name="greenarrow" style="cursor: pointer;" onclick="document.renameform_#idname#.submit();" align="absmiddle"> &nbsp;<img src="images/abort.png" name="Abort" alt="Abort" title="Abort" style="cursor:pointer;" onclick="Javascript:HideRenameForm('#idname#')" align="absmiddle">
            </form>
            </span> </div></td>
        <td class="menu_cell" onclick="window.location.href = 'index.cfm?c=admindocs&a=edit&page_name=#name#&f=#f#&dir=#dir#';">#dateformat(qfiles.dateLastModified, "mm/dd/yyyy")# #timeformat(qfiles.dateLastModified, "hh:mm tt")#</td>
        <td class="menu_cell" style="text-align: right;"><span id="actions"> <a href = "index.cfm?c=admindocs&a=edit&page_name=#name#&f=#f#&dir=#dir#"><img src="images/edit.png" border="0" alt="Edit Page" title="Edit Page" /></a>&nbsp; <a href = "index.cfm?c=admindocs&a=duplicate&filen=#name#&f=#f#&dir=#dir#"><img src="images/copy.png" border="0" alt="Duplicate Page" title="Duplicate Page" /></a>&nbsp; <a href = "##" onclick="javascript:ShowRenameForm('#idname#');"><img src="images/refresh.png" alt="Rename" title="Rename" border="0" /></a>&nbsp; <a href = "##" onclick="javascript:ConfirmDeleteAdminPage('#f##dir#','#name#');"><img src="images/delete.png" border="0" alt="Delete" title="Delete" /></a></span>
          </div>
        </td>
      </tr>
    </cfoutput>
  </cfloop>
  <cfif qfiles.recordcount IS 0>
    <tr>
      <td colspan="3"><div id="messages_info">No pages exist in this folder</div></td>
    </tr>
  </cfif>
</table>
